<?php
class Msimple extends CI_Model {

    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    function get_auto_produksi($q){
      $q = strtolower($q);
      $query = "
        SELECT *
        FROM d_product_produksi
        WHERE 
        LOWER(name) LIKE '%{$q}%'
        ";
//print $query;
      $data = $this->db->query($query)->result();
      $items = array();
      if(is_array($data)){
        foreach($data as $dt){
          $items[$dt->name] = $dt->id_product_produksi;
        }
      }
      return $items;
    }
    
    function get_auto_supplier($q, $id_produksi){
      $q = strtolower($q);
      $query = "
        SELECT B.*
        FROM d_product_supplier_produksi AS A
        JOIN m_supplier AS B ON A.id_supplier = B.id_supplier
        WHERE 
        LOWER(B.title) LIKE '%{$q}%' AND A.id_product_produksi = {$id_produksi}
        ";
//print $query;
      $data = $this->db->query($query)->result();
      $items = array();
      if(is_array($data)){
        foreach($data as $dt){
          $items[$dt->title] = $dt->id_supplier;
        }
      }
      return $items;
    }
}
?>
